package com.xckj.teacher.ui.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xckj.teacher.R;
import com.xckj.teacher.databinding.FragmentTaskBinding;
import com.xckj.teacher.event.OpenBottomTabEvent;
import com.xckj.teacher.event.UpdateEvent;
import com.xckj.teacher.framework.BaseFragment;
import com.xckj.teacher.global.Constant;
import com.xckj.teacher.util.CacheUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @Author: ChenYao
 * @Describe: 作业
 * @Date: 2024/4/10 22:42
 */
public class TaskFragment extends BaseFragment<FragmentTaskBinding> {
    @Override
    protected int loadLayout() {
        return R.layout.fragment_task;
    }

    @Override
    protected int setStatusBarColor() {
        return R.color.home_top_status;
    }

    protected boolean isStatusBarDarkFont() {
        return false;
    }


    @Override
    protected void initData() {
        EventBus.getDefault().register(this);
        initWebView();
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initWebView() {
        dataBinding.webView.setHorizontalScrollBarEnabled(false);
        dataBinding.webView.loadUrl(String.format(Constant.TASK_H5_URL, CacheUtil.INSTANCE.getToken()));
        Log.e("CY_", String.format(Constant.TASK_H5_URL, CacheUtil.INSTANCE.getToken()));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void updateData(UpdateEvent event) {
        initWebView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
